<style>
#auto div
{
	margin-bottom: 3px;
}

#validate div
{
	margin-bottom: 3px;
}
</style>
<script>
var autoItem = '<select id="" name="autoFields[]" onchange="cloneAuto(event)" ondblclick="" class="" ><option value="" >请选择字段</option><?php  foreach($FieldList as $key=>$val) { ?><option value="<?php echo $key ?>"><?php echo $val ?></option><?php } ?></select> <input type="text" name="content[]" value="填充内容" onfocus="this.value=\'\'" size="10"> <select name="when[]"><option value="ADD" selected>ADD</option><option value="UPDATE">UPDATE</option><option value="ALL">ALL</option></select> <select name="autotype[]"><option value="string" selected>string</option><option value="function">function</option><option value="callback">callback</option><option value="field">field</option></select>';

var validateItem = '<select id="" name="validateFields[]" onchange="cloneValidate(event)" ondblclick="" class="" ><option value="" >请选择字段</option><?php  foreach($FieldList as $key=>$val) { ?><option value="<?php echo $key ?>"><?php echo $val ?></option><?php } ?></select> <input type="text" name="rule[]" value="require" size="10"> <input type="text" name="message[]" value="错误消息" onfocus="this.value=\'\'" size="10"> <select name="condition[]"><option value="EXISTS_TO_VAILIDATE" selected>存在字段则验证</option><option value="MUST_TO_VALIDATE">必须验证</option><option value="VALUE_TO_VAILIDATE">值不为空则验证</option></select> <select name="append[]"><option value="regex" selected>regex</option><option value="function">function</option><option value="callback">callback</option><option value="confirm">confirm</option><option value="equal">equal</option><option value="in">in</option><option value="unique">unique</option></select>';

function cloneAuto(event)
{
	var select = event.srcElement == undefined ? event.target : event.srcElement; 
	var div = document.createElement("div");
	div.innerHTML = autoItem;
	select.parentNode.appendChild(div);
}

function cloneValidate(event)
{
	var select = event.srcElement == undefined ? event.target : event.srcElement; 
	var div = document.createElement("div");
	div.innerHTML = validateItem;
	select.parentNode.appendChild(div);
}

function getFields()
{
	var url = '/TPToolbox/index.php/ModelGen/index<?php echo (C("PATH_DEPR")); ?>Model<?php echo (C("PATH_DEPR")); ?>'+$('#model').val();
	window.location = url;
}
</script>
<div style="float:left">
    <form method="post" action="<?php echo url('save');?>">
        <fieldset>
            <legend>生成Model文件</legend>
			快捷选择Model名称<select id="model" name="model" onchange="getFields()" ondblclick="" class="" ><option value="" >请选择模型</option><?php  foreach($ModelList as $key=>$val) { ?><?php if(!empty($_GET['Model']) && ($_GET['Model'] == $key || in_array($key,$_GET['Model']))) { ?><option selected="selected" value="<?php echo $key ?>"><?php echo $val ?></option><?php }else { ?><option value="<?php echo $key ?>"><?php echo $val ?></option><?php } ?><?php } ?></select><br />
            <?php echo ($_SESSION['prj_path']); ?>/Lib/Model/
			<input type="text" name="modelname" size="15" value="<?php echo ($_GET['Model']); ?>">
			Model.class.php
			<p><input type="checkbox" class="checkbox" name="overwrite"> 覆盖同名文件</p>
			<p><input type="checkbox" class="checkbox" name="viewmodel"> ViewModel</p>
			<p id="auto">
			自动填充
			<div>
				<select id="" name="autoFields[]" onchange="cloneAuto(event)" ondblclick="" class="" ><option value="" >请选择字段</option><?php  foreach($FieldList as $key=>$val) { ?><option value="<?php echo $key ?>"><?php echo $val ?></option><?php } ?></select>
				<input type="text" name="content[]" value="填充内容" onfocus="this.value=''" size="10">
				<select name="when[]">
					<option value="ADD" selected>ADD</option>
					<option value="UPDATE">UPDATE</option>
					<option value="ALL">ALL</option>
				</select>
				<select name="autotype[]">
					<option value="string" selected>string</option>
					<option value="function">function</option>
					<option value="callback">callback</option>
					<option value="field">field</option>
				</select>
			</div>
			</p>
			<p id="validate">
			自动校验
			<div>
				<select id="" name="validateFields[]" onchange="cloneValidate(event)" ondblclick="" class="" ><option value="" >请选择字段</option><?php  foreach($FieldList as $key=>$val) { ?><option value="<?php echo $key ?>"><?php echo $val ?></option><?php } ?></select>
				<input type="text" name="rule[]" value="require" size="10">
				<input type="text" name="message[]" value="错误消息" onfocus="this.value=''" size="10">
				<select name="condition[]">
					<option value="EXISTS_TO_VAILIDATE" selected>存在字段则验证</option>
					<option value="MUST_TO_VALIDATE">必须验证</option>
					<option value="VALUE_TO_VAILIDATE">值不为空则验证</option>
				</select>
				<select name="append[]">
					<option value="regex" selected>regex</option>
					<option value="function">function</option>
					<option value="callback">callback</option>
					<option value="confirm">confirm</option>
					<option value="equal">equal</option>
					<option value="in">in</option>
					<option value="unique">unique</option>
				</select>
			</div>
			</p>
			<p>
			关联查找<BR>
			<select name="linktype">
				<option value="">请选择关联类型</option>
				<option value="HAS_MANY">HAS_MANY</option>
				<option value="HAS_ONE">HAS_ONE</option>
				<option value="BELONGS_TO">BELONGS_TO</option>
				<option value="MANY_TO_MANY">MANY_TO_MANY</option>
			</select>
			关联变量名<input type="text" name="linkvar" value="linkvar" onfocus="this.value=''">
			</p>
            <p><input type="submit" name="submit" value="提交" /></p>
        </fieldset>
    <?php if(C("TOKEN_ON")):?><input type="hidden" name="<?php echo C("TOKEN_NAME");?>" value="<?php echo Session::get(C("TOKEN_NAME")); ?>"/><?php endif;?></form>
</div>